home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / ThreadLibrary-1.0 / Source / Libraries / regppc.s < prev    next >
Text File  |  1995-06-08  |  3KB  |  145 lines

  1. #    Based on the file "setjmp.s" from Metrowerks CodeWarrior 5. The original
  2. #    "setjmp.s" is copyright © 1993 Metrowerks Inc.
  3.  
  4. #    Assembly language routines for saving and restoring
  5. #    registers, for use from the PowerPC version of Thread
  6. #    Library. There are two functions:
  7. #
  8. #        ThreadRegistersPPCSave        similar to setjmp;
  9. #        ThreadRegistersPPCRestore    similar to longjmp.
  10. #
  11. #    The pointer passed to ThreadRegistersPPCSave and ThreadRegistersPPCRestore
  12. #    should be defined as an array of long integers. See the file "regppc.h" for
  13. #    the actual definitions.
  14. #
  15. #    The pointer passed to ThreadRegistersPPCSave and ThreadRegistersPPCRestore
  16. #    corresponds to the following structure.
  17. #
  18. #        typedef struct ThreadRegistersPPCType {
  19. #            unsigned long    unused;        //    0: unused
  20. #            unsigned long    PC;            //    4: saved PC
  21. #            unsigned long    CR;            //    8: saved CR
  22. #            unsigned long    SP;            // 12: saved SP
  23. #            unsigned long    RTOC;        // 16: saved RTOC
  24. #            unsigned long    GPRs[19];    // 20: saved r13-r31
  25. #            double            FPRs[18];    // 96: saved fp14-fp31
  26. #            double            FPSCR;        //240: saved FPSCR
  27. #        };
  28. #
  29. #    To assemble this file:
  30. #
  31. #        ppcasm regppc.s -o regppc.xcoff
  32. #
  33.  
  34.     dialect    powerpc
  35.  
  36. #
  37. #    Export function names.
  38. #
  39.  
  40.     toc
  41.     
  42.     csect    ThreadRegistersPPCSave[DS]
  43.     export    ThreadRegistersPPCSave[DS]
  44.     dc.l    .ThreadRegistersPPCSave[PR]
  45.     dc.l    TOC[TC0]
  46.  
  47.     csect    ThreadRegistersPPCRestore[DS]
  48.     export    ThreadRegistersPPCRestore[DS]
  49.     dc.l    .ThreadRegistersPPCRestore[PR]
  50.     dc.l    TOC[TC0]
  51.  
  52. #
  53. #    ThreadRegistersPPCSave
  54. #
  55. #    On entry:
  56. #
  57. #        R3 points to a ThreadRegistersPPCType structure.
  58. #
  59. #    On exit:
  60. #
  61. #        R3 is 0.
  62. #
  63.     csect    .ThreadRegistersPPCSave[PR]
  64.     export    .ThreadRegistersPPCSave[PR]
  65.     mflr    r5
  66.     mfcr    r6
  67.     stw        r5,4(r3)        #    save PC (LR)
  68.     stw        r6,8(r3)        #    save CR
  69.     stw        SP,12(r3)        #    save SP
  70.     stw        RTOC,16(r3)        #    save RTOC
  71.     stmw    r13,20(r3)        #    save r13-r31
  72.     mffs    fp0
  73.     stfd    fp14,96(r3)        #    save fp14-fp31
  74.     stfd    fp15,104(r3)
  75.     stfd    fp16,112(r3)
  76.     stfd    fp17,120(r3)
  77.     stfd    fp18,128(r3)
  78.     stfd    fp19,136(r3)
  79.     stfd    fp20,144(r3)
  80.     stfd    fp21,152(r3)
  81.     stfd    fp22,160(r3)
  82.     stfd    fp23,168(r3)
  83.     stfd    fp24,176(r3)
  84.     stfd    fp25,184(r3)
  85.     stfd    fp26,192(r3)
  86.     stfd    fp27,200(r3)
  87.     stfd    fp28,208(r3)
  88.     stfd    fp29,216(r3)
  89.     stfd    fp30,224(r3)
  90.     stfd    fp31,232(r3)
  91.     stfd    fp0,240(r3)        #    save FPSCR
  92.     li        r3,0
  93.     blr
  94.  
  95. #    end ThreadRegistersPPCSave.
  96.  
  97. #
  98. #    ThreadRegistersPPCRestore
  99. #
  100. #    On entry:
  101. #        
  102. #        R3 points to a ThreadRegistersPPCType structure
  103. #        R4 contains the return value.
  104. #
  105. #    On exit:
  106. #
  107. #        R3 contains 1 if R4 was 0, otherwise it contains the value from R4.
  108. #
  109.     csect    .ThreadRegistersPPCRestore[PR]
  110.     export    .ThreadRegistersPPCRestore[PR]
  111.     lwz        r5,4(r3)
  112.     lwz        r6,8(r3)
  113.     mtlr    r5                #    restore PC (LR)
  114.     mtcrf    255,r6            #    restore CR
  115.     lwz        SP,12(r3)        #    restore SP
  116.     lwz        RTOC,16(r3)        #    restore RTOC
  117.     lmw        r13,20(r3)        #    restore r13-r31
  118.     lfd        fp14,96(r3)        #    restore fp14-fp31
  119.     lfd        fp15,104(r3)
  120.     lfd        fp16,112(r3)
  121.     lfd        fp17,120(r3)
  122.     lfd        fp18,128(r3)
  123.     lfd        fp19,136(r3)
  124.     lfd        fp20,144(r3)
  125.     lfd        fp21,152(r3)
  126.     lfd        fp22,160(r3)
  127.     lfd        fp23,168(r3)
  128.     lfd        fp24,176(r3)
  129.     lfd        fp25,184(r3)
  130.     lfd        fp26,192(r3)
  131.     lfd        fp27,200(r3)
  132.     lfd        fp28,208(r3)
  133.     lfd        fp29,216(r3)
  134.     lfd        fp30,224(r3)
  135.     lfd        fp0,240(r3)
  136.     lfd        fp31,232(r3)
  137.     cmpwi    r4,0
  138.     mr        r3,r4
  139.     mtfsf    255,fp0            #    restore FPSCR
  140.     bnelr                    #    return value in R4
  141.     li        r3,1            #    return 1
  142.     blr
  143.  
  144. #    end ThreadRegistersPPCRestore.
  145.